package com.shermanzhou.mock;

import lombok.Builder;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * @author zhouchaoqun
 * @date 2019/4/12 3:05 PM
 */
@Data
@Builder
public class User {
    private String id;
    private String name;
    private int age;

    private static Map<String, User> users = new HashMap<>();

    public User findById(String id) {
        return users.get(id);
    }

    public String createUser(String name, int age) {
        String uuid = UUID.randomUUID().toString();
        User user = User.builder().id(uuid).name(name).age(age).build();
        users.put(uuid, user);
        return uuid;
    }

    public String createUser(User user) {
        String uuid = UUID.randomUUID().toString();
        user.setId(uuid);
        users.put(uuid, user);
        return uuid;
    }
}
